use linera_sdk::graphql::GraphQLMutationRoot;
use linera_sdk::linera_base_types::ChainId;
use serde::{Deserialize, Serialize};

use crate::{Key, OwnPost};

#[derive(Debug, Deserialize, Serialize, GraphQLMutationRoot)]
pub enum Operation {
    /// Request to be subscribed to another chain
    Subscribe { chain_id: ChainId },
    /// Request to be unsubscribed from another chain
    Unsubscribe { chain_id: ChainId },
    /// Send a new post to everyone who subscribed to us
    Post {
        text: String,
        image_url: Option<String>,
    },
    /// Like a post
    Like { key: Key },
    /// Comment a post
    Comment { key: Key, comment: String },
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub enum Message {
    /// The origin chain wants to subscribe to the target chain
    Subscribe,
    /// The origin chain wants to unsubscribe to the target chain
    Unsubscribe,
    /// The origin chain made a post, and the target chain is subscribed
    Post { index: u32, post: OwnPost },
    /// A chain liked a post
    Like { key: Key },
    /// A chain commented on a post
    Comment {
        key: Key,
        chain_id: ChainId,
        comment: String,
    },
}
